home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 2 / BBS in a box - Trilogy II.iso / AMUG Info / Apple / MacsBug 6.2.2 / dcmds / C Samples / Drvr.c next >
Encoding:
C/C++ Source or Header  |  1991-11-19  |  4.9 KB  |  239 lines  |  [TEXT/MPS ]

  1. /*     drvr.c
  2.     This is the Unit Table dcmd.
  3.  
  4.     Copyright © 1988 Apple Computer, Inc.  All rights reserved.
  5.  
  6.     Modification history:
  7.          7Dec88 sad        show driver version
  8.         29Nov88 sad        revised for new dcmd names
  9.         13Oct88 sad        written from file.c
  10.  
  11.     The following MPW commands will build the dcmd and copy it to the
  12.     "Debugger Prefs" file in the System folder. The dcmd's name in
  13.     MacsBug will be the name of the file built by the Linker.
  14.     You must first copy dcmd.h, dcmdGlue.a.o and DRunTime.o from the
  15.     C Samples folder into this folder.
  16.  
  17.     C Put.c
  18.     C Drvr.c
  19.     Link dcmdGlue.a.o Drvr.c.o put.c.o DRuntime.o "{Libraries}"Interface.o -o Drvr
  20.     BuildDcmd Drvr 1000
  21.     Echo 'include "Drvr";'    |    Rez -a -o "{systemFolder}Debugger Prefs"
  22. */
  23.  
  24. #ifdef USESTDIO
  25. #include <stdio.h>
  26. #endif
  27.  
  28. #include <Types.h>
  29. #include <Memory.h>
  30. #include <Devices.h>
  31. #include <SysEqu.h>
  32.  
  33. #include "dcmd.h"
  34. #include "put.h"
  35.  
  36.  
  37. typedef struct DRVR
  38.     {
  39.     short drvrFlags;
  40.     short drvrDelay;
  41.     short drvrEMask;
  42.     short drvrMenu;
  43.     short drvrOpen;
  44.     short drvrPrime;
  45.     short drvrCtl;
  46.     short drvrStatus;
  47.     short drvrClose;
  48.     Str255 drvrName;
  49.     } DRVR;
  50.  
  51.  
  52. static void DrawHdr()
  53. {
  54. //                             1         2         3         4         5         6         7
  55. //                    12345678901234567890123456789012345678901234567890123456789012345678901234567890
  56.     dcmdDrawLine("\pdRef dNum Driver      Flg  Ver qHead Storage Window Dely  Drvr at DCE at");
  57. }
  58.  
  59.  
  60. static void DrawDCE(int dref, AuxDCE* dcep)
  61. {
  62.     DRVR*    drvrp;
  63.  
  64.     PutUHexWord(dref);
  65.     PutSpace();
  66.     PutUHexWord(~dref);
  67.     PutSpace();
  68.     if (dcep->dCtlFlags & 0x40)
  69.         {
  70.         if (dcep->dCtlDriver)
  71.             {
  72.             drvrp = *(DRVR**)dcep->dCtlDriver;
  73.             if (drvrp) PutPStrTruncTo(drvrp->drvrName,21);
  74.             else PutPStrTruncTo("\p-purged-",21);
  75.             }
  76.         else
  77.             {
  78.             PutPStrTruncTo("\p",21);
  79.             };
  80.         }
  81.     else
  82.         {
  83.         if (dcep->dCtlDriver)
  84.             {
  85.             drvrp = (DRVR*)dcep->dCtlDriver;
  86.             PutPStrTruncTo(drvrp->drvrName,21);
  87.             }
  88.         else
  89.             {
  90.             PutPStrTruncTo("\p",21);
  91.             };
  92.         };
  93.     PutSpace();
  94.     PutChar((dcep->dCtlFlags & 0x80) ? 'B' : 'b');
  95.     PutChar((dcep->dCtlFlags & 0x40) ? 'H' : 'P');
  96.     PutChar((dcep->dCtlFlags & 0x20) ? 'O' : 'C');
  97.     PutSpace();
  98.     PutUDecTo((unsigned char)dcep->dCtlQHdr.qFlags,30);
  99.     PutSpace();
  100.     PutUHexZTo((unsigned long)dcep->dCtlQHdr.qHead,6,36);
  101.     PutSpace();
  102.     PutUHexZTo((unsigned long)dcep->dCtlStorage,6,44);
  103.     PutSpace();
  104.     PutUHexZTo((unsigned long)dcep->dCtlWindow,6,51);
  105.     PutSpace();
  106.     PutUHexWord((unsigned long)dcep->dCtlDelay);
  107.     PutSpace();
  108.     PutUHexZTo((unsigned long)drvrp,6,65);
  109.     PutSpace();
  110.     PutUHexZTo((unsigned long)dcep,6,72);
  111.     PutLine();
  112.     if (dref != dcep->dCtlRefNum)
  113.         {
  114.         // this case actually happens normally for drvr fffe .Sony for the HD20 (pre-SCSI)
  115.         PutPStr("\p   that is strange:  dCtlRefNum = ");
  116.         PutUHexWord(dcep->dCtlRefNum);
  117.         PutLine();
  118.         }
  119. } // DrawDCE
  120.  
  121. // EJECT
  122.  
  123. pascal void CommandEntry(dcmdBlock* paramPtr)
  124. {
  125.     switch (paramPtr->request)
  126.         {
  127.         case dcmdInit:
  128.             break;
  129.  
  130.         case dcmdHelp:
  131.             dcmdDrawLine("\pdrvr [refnum|num]");
  132.             dcmdDrawLine("\p   Displays driver information for the given refnum or all installed drivers.");
  133.             dcmdDrawLine("\p      Flags are B/b=Busy, H/P=Handle/Ptr, O/C=Open/Closed.");
  134.             break;
  135.  
  136.         case dcmdDoIt:
  137.             {
  138.             Boolean doOne = false;
  139.             long dref;
  140.             int numdces;
  141.  
  142.             dcmdSwapWorlds();
  143.  
  144.             dcmdDrawLine("\pDisplaying Driver Control Entries");
  145.  
  146.           // get low-memory values after dcmdSwapWorlds()
  147.             numdces = *(unsigned short *)UnitNtryCnt;
  148.  
  149.             (void)dcmdGetNextExpression(&dref, &doOne);
  150.  
  151.             if (doOne)
  152.                 {
  153.                 int dnum;
  154.                 dref = (short)dref;
  155.                 if (dref < 0) dnum = ~dref;
  156.                 else
  157.                     {
  158.                     dnum = dref;
  159.                     dref = ~dref;
  160.                     }
  161.                 if (dnum > numdces)
  162.                     {
  163. #ifdef USESTDIO
  164.                     Str255 line;
  165.                     sprintf(line,"bad refnum 0x%.4x",(unsigned short)dref);
  166.                     dcmdDrawLine((Str255)c2pstr(&line));
  167. #else
  168.                     PutPStr("\pbad refnum ");
  169.                     PutUHexWord(dref);
  170.                     PutSpace();
  171.                     PutUHexWord(~dref);
  172.                     PutLine();
  173. #endif
  174.                     }
  175.                 else
  176.                     {
  177.                     AuxDCE** dceh = (*(AuxDCE****)UTableBase)[dnum];
  178.                     if (dceh)
  179.                         {
  180.                         DrawHdr();
  181.                         DrawDCE(dref,*dceh);
  182.                         }
  183.                     else
  184.                         {
  185.                         PutPStr("\pDriver ");
  186.                         PutUHexWord(dref);
  187.                         PutSpace();
  188.                         PutUHexWord(~dref);
  189.                         PutPStr("\p is not in installed");
  190.                         PutLine();
  191.                         }
  192.                     }
  193.                 }
  194.             else
  195.                 {
  196.                 int dcesused = 0;
  197.                 int dnum;
  198.                 AuxDCE*** dcehp;
  199.                 Boolean foundOne = false;
  200.                 for (dnum = 0, dcehp = *(AuxDCE****)UTableBase;
  201.                      dnum < numdces;
  202.                      dnum++, dcehp++)
  203.                     {
  204.                     if (*dcehp)
  205.                         {
  206.                         dcesused++;
  207.                         if (!foundOne)
  208.                             {
  209.                             DrawHdr();
  210.                             foundOne = true;
  211.                             }
  212.                         DrawDCE(~dnum,**dcehp);
  213.                         }
  214.                     if (paramPtr->aborted) break;
  215.                     }
  216.                 if (!paramPtr->aborted)
  217.                     {
  218.                     PutUDec(numdces);
  219.                     PutPStr("\p Unit Table entries, ");
  220.                     PutUDec(dcesused);
  221.                     PutPStr("\p in use, ");
  222.                     PutUDec(numdces - dcesused);
  223.                     PutPStr("\p free");
  224.                     PutLine();
  225.                     }
  226.                 }    
  227.  
  228.             dcmdSwapWorlds();
  229.             }
  230.             break;
  231.  
  232.         default:
  233.             PutPStr("\punknown request ");
  234.             PutUDec(paramPtr->request);
  235.             PutLine();
  236.             break;
  237.         }
  238. } // CommandEntry
  239.